/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PanelDarAltaGrupo.java
 *
 * Created on 29/10/2014, 10:17:14 AM
 */
package mx.com.ugto.caadi.asistencias.gui;

import mx.com.ugto.caadi.asistencias.bean.Nivel;
import java.util.List;
import javax.swing.DefaultComboBoxModel;
import mx.com.ugto.caadi.asistencias.bean.Grupo;
import mx.com.ugto.caadi.asistencias.bean.Maestro;
import mx.com.ugto.caadi.asistencias.bean.Materia;
import mx.com.ugto.caadi.asistencias.dao.GrupoDAO;
import mx.com.ugto.caadi.asistencias.dao.MaestroDAO;
import mx.com.ugto.caadi.asistencias.dao.MateriaDAO;
import mx.com.ugto.caadi.asistencias.dao.NivelDAO;
import static mx.com.ugto.caadi.asistencias.util.GUIUtil.*;

/**
 *
 * @author Maestria
 */
public class PanelDarAltaGrupo extends javax.swing.JPanel {

    /** Creates new form PanelDarAltaGrupo */
    public PanelDarAltaGrupo() {
        initComponents();
    }

    void obtenerFoco() {
        cmbNivel.requestFocusInWindow();
    }

    public void cargarDatosGenerales() {
        //--
        NivelDAO daoNiveles = new NivelDAO();
        List<Nivel> lstNiveles = daoNiveles.findAll();
        cmbNivel.setModel(new DefaultComboBoxModel(lstNiveles.toArray()));
        //--
        GrupoDAO daoGrupos = new GrupoDAO();
        List<Grupo> lstGrupos = daoGrupos.findAll();
        cmbGrupo.setModel(new DefaultComboBoxModel(lstGrupos.toArray()));
        //--
        MaestroDAO daoMaestros = new MaestroDAO();
        List<Maestro> lstMaestros = daoMaestros.findAll();
        cmbMaestro.setModel(new DefaultComboBoxModel(lstMaestros.toArray()));
        //--
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lblNivel = new javax.swing.JLabel();
        cmbNivel = new javax.swing.JComboBox();
        lblGrupo = new javax.swing.JLabel();
        cmbGrupo = new javax.swing.JComboBox();
        lblMaestro = new javax.swing.JLabel();
        cmbMaestro = new javax.swing.JComboBox();
        lblPeriodo = new javax.swing.JLabel();
        lblSemestre = new javax.swing.JLabel();
        lblTitulo = new javax.swing.JLabel();
        lblObservacion = new javax.swing.JLabel();
        scrObservacion = new javax.swing.JScrollPane();
        txpObservacion = new javax.swing.JTextPane();
        ychSemestre = new com.toedter.calendar.JYearChooser();
        btnLimpiar = new javax.swing.JButton();
        btnGuardar = new javax.swing.JButton();
        spnSemestre = new javax.swing.JSpinner();

        lblNivel.setText("Nivel:");

        cmbNivel.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        lblGrupo.setText("Grupo:");

        cmbGrupo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        lblMaestro.setText("Maestro:");

        cmbMaestro.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        lblPeriodo.setText("Periodo:");

        lblSemestre.setText("Semestre:");

        lblTitulo.setFont(new java.awt.Font("Tahoma", 1, 12));
        lblTitulo.setText("DAR DE ALTA GRUPO");

        lblObservacion.setText("Observación:");

        scrObservacion.setViewportView(txpObservacion);

        btnLimpiar.setText("Limpiar");
        btnLimpiar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLimpiarActionPerformed(evt);
            }
        });

        btnGuardar.setText("Guardar");
        btnGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGuardarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lblTitulo, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 491, Short.MAX_VALUE)
                    .addComponent(lblObservacion, javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(btnGuardar)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(btnLimpiar))
                        .addComponent(scrObservacion, javax.swing.GroupLayout.PREFERRED_SIZE, 337, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(lblNivel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cmbNivel, 0, 71, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(lblGrupo)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cmbGrupo, 0, 71, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(lblMaestro)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cmbMaestro, javax.swing.GroupLayout.PREFERRED_SIZE, 154, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(lblPeriodo)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(ychSemestre, javax.swing.GroupLayout.DEFAULT_SIZE, 71, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(lblSemestre)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(spnSemestre, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {lblGrupo, lblMaestro, lblNivel, lblPeriodo, lblSemestre});

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cmbGrupo, cmbNivel, spnSemestre, ychSemestre});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblTitulo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblNivel)
                    .addComponent(cmbNivel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblGrupo)
                    .addComponent(cmbGrupo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblMaestro)
                    .addComponent(cmbMaestro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(ychSemestre, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lblPeriodo))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE, false)
                    .addComponent(lblSemestre)
                    .addComponent(spnSemestre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(lblObservacion)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(scrObservacion, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnLimpiar)
                    .addComponent(btnGuardar))
                .addGap(82, 82, 82))
        );
    }// </editor-fold>//GEN-END:initComponents

private void btnGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuardarActionPerformed
// TODO add your handling code here:
    guardarMateria();
}//GEN-LAST:event_btnGuardarActionPerformed

private void btnLimpiarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLimpiarActionPerformed
// TODO add your handling code here:
    limpiar(this);
}//GEN-LAST:event_btnLimpiarActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnGuardar;
    private javax.swing.JButton btnLimpiar;
    private javax.swing.JComboBox cmbGrupo;
    private javax.swing.JComboBox cmbMaestro;
    private javax.swing.JComboBox cmbNivel;
    private javax.swing.JLabel lblGrupo;
    private javax.swing.JLabel lblMaestro;
    private javax.swing.JLabel lblNivel;
    private javax.swing.JLabel lblObservacion;
    private javax.swing.JLabel lblPeriodo;
    private javax.swing.JLabel lblSemestre;
    private javax.swing.JLabel lblTitulo;
    private javax.swing.JScrollPane scrObservacion;
    private javax.swing.JSpinner spnSemestre;
    private javax.swing.JTextPane txpObservacion;
    private com.toedter.calendar.JYearChooser ychSemestre;
    // End of variables declaration//GEN-END:variables

    private void guardarMateria() {
        Materia materia = new Materia();
        Nivel nivel = (Nivel) cmbNivel.getSelectedItem();
        Grupo grupo = (Grupo) cmbGrupo.getSelectedItem();
        Maestro maestro = (Maestro) cmbMaestro.getSelectedItem();
        int periodo = ychSemestre.getYear();
        int semestre = (Integer) spnSemestre.getValue();
        materia.setNivel(nivel);
        materia.setGrupo(grupo);
        materia.setMaestro(maestro);
        materia.setDatPeriodo(periodo);
        materia.setNumSemestre(semestre);
        MateriaDAO dao = new MateriaDAO();
        dao.create(materia);
    }
}
